package com.atkinsglobal.basic.validation;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

public class JazuValidator implements Validator {

	@Override
	public boolean supports(Class<?> arg0) {

		return ModelComponent.class.isAssignableFrom(arg0);
	}

	@Override
	public void validate(Object arg0, Errors err) {

		ModelComponent m = (ModelComponent) arg0;
		ValidationUtils.rejectIfEmptyOrWhitespace(err, "jazu", "jazu.empty");
		if(!m.getJazuCode().startsWith("#")){
			
			err.rejectValue("jazu", "jazu.bad");
		}
		
	}

}
